convert html to Format class. (#837)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sat, 29 Jan 2022 16:31:01 +0000 (09:31 -0700)
committerGitHub <noreply@github.com>
Sat, 29 Jan 2022 16:31:01 +0000 (09:31 -0700)
* convert html to Format class.

* add default init.

* capability comment

CMakeLists.txt
GPSBabel.pro
html.cc
html.h [new file with mode: 0644]
vecs.h

index a8a4a19cd447ca123be337b10fa224507ef324ad..0e0a1f80bce45b98c73d5f1ce2858f06251b407f 100644 (file)
@@ -241,6 +241,7 @@ set(HEADERS
   grtcirc.h
   heightgrid.h
   holux.h
+  html.h
   inifile.h
   kml.h
   legacyformat.h
index 035a8067bb5c1d74edf2b0501a30ad299f668e18..6e2a6d61914e9f42c2758fca01c849eb37d3027c 100644 (file)
@@ -228,6 +228,7 @@ HEADERS =  \
   grtcirc.h \
   heightgrid.h \
   holux.h \
+  html.h \
   inifile.h \
   kml.h \
   legacyformat.h \
diff --git a/html.cc b/html.cc
index 53b9da72cdcb727b582f1919587f0c2982012680..1db9f50835fb0984b604bcaa7b67ec8d36c6c0ef 100644 (file)
--- a/html.cc
+++ b/html.cc
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
 
-#include <cstdint>
-#include <ctime>                   // for localtime
+#include "html.h"
 
 #include <QString>                 // for QString, operator!=
-#include <QVector>                 // for QVector
 #include <Qt>                      // for CaseInsensitive
 
-#include "defs.h"
-#include "formspec.h"              // for FsChainFind, kFsGpx
-#include "gbfile.h"                // for gbfprintf, gbfclose, gbfopen, gbfputs, gbfile
+#include <cstdint>                 // for int32_t
+#include <ctime>                   // for localtime, time_t, tm
+
+#include "defs.h"                  // for Waypoint, xfree, geocache_data, html_entitize, CSTR, pretty_deg_format, rot13, strip_nastyhtml, waypt_disp_all, utf_string, METERS_TO_FEET, gpsbabel_testmode, gs_get_cachetype, gs_get_container, mkshort_del_handle, mkshort_from_wpt, mkshort_new_handle
+#include "formspec.h"              // for FormatSpecificDataList, kFsGpx
+#include "gbfile.h"                // for gbfprintf, gbfclose, gbfopen, gbfputs
 #include "jeeps/gpsmath.h"         // for GPS_Math_WGS84_To_UTM_EN
 #include "src/core/datetime.h"     // for DateTime
-#include "src/core/xmltag.h"       // for xml_findfirst, xml_attribute, xml_tag, fs_xml, xml_findnext
-
+#include "src/core/xmltag.h"       // for xml_findfirst, xml_tag, xml_attribute, fs_xml, xml_findnext
 
-static gbfile* file_out;
-static short_handle mkshort_handle;
-
-static char* stylesheet = nullptr;
-static char* html_encrypt = nullptr;
-static char* includelogs = nullptr;
-static char* degformat = nullptr;
-static char* altunits = nullptr;
 
 #define MYNAME "HTML"
 
-static
-QVector<arglist_t> html_args = {
-  {
-    "stylesheet", &stylesheet,
-    "Path to HTML style sheet", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr
-  },
-  {
-    "encrypt", &html_encrypt,
-    "Encrypt hints using ROT13", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
-  },
-  {
-    "logs", &includelogs,
-    "Include groundspeak logs if present", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
-  },
-  {
-    "degformat", &degformat,
-    "Degrees output as 'ddd', 'dmm'(default) or 'dms'", "dmm", ARGTYPE_STRING, ARG_NOMINMAX, nullptr
-  },
-  {
-    "altunits", &altunits,
-    "Units for altitude (f)eet or (m)etres", "m", ARGTYPE_STRING, ARG_NOMINMAX, nullptr
-  },
-};
-
-
-
-static void
-wr_init(const QString& fname)
+void
+HtmlFormat::wr_init(const QString& fname)
 {
   file_out = gbfopen(fname, "w", MYNAME);
   mkshort_handle = mkshort_new_handle();
 }
 
-static void
-wr_deinit()
+void
+HtmlFormat::wr_deinit()
 {
   gbfclose(file_out);
   mkshort_del_handle(&mkshort_handle);
 }
 
-static void
-html_disp(const Waypoint* wpt)
+void
+HtmlFormat::html_disp(const Waypoint* wpt) const
 {
   int32_t utmz;
   double utme;
@@ -227,8 +193,8 @@ html_disp(const Waypoint* wpt)
   gbfprintf(file_out, "</td></tr></table>\n");
 }
 
-static void
-html_index(const Waypoint* wpt)
+void
+HtmlFormat::html_index(const Waypoint* wpt) const
 {
   char* sn = html_entitize(wpt->shortname);
   char* d = html_entitize(wpt->description);
@@ -239,8 +205,8 @@ html_index(const Waypoint* wpt)
   xfree(d);
 }
 
-static void
-data_write()
+void
+HtmlFormat::write()
 {
   setshort_length(mkshort_handle, 6);
 
@@ -266,29 +232,20 @@ data_write()
   gbfprintf(file_out, "<body>\n");
 
   gbfprintf(file_out, "<p class=\"index\">\n");
-  waypt_disp_all(html_index);
+
+  auto html_index_lambda = [this](const Waypoint* waypointp)->void {
+    html_index(waypointp);
+  };
+
+  waypt_disp_all(html_index_lambda);
   gbfprintf(file_out, "</p>\n");
 
-  waypt_disp_all(html_disp);
+  auto html_disp_lambda = [this](const Waypoint* waypointp)->void {
+    html_disp(waypointp);
+  };
+  waypt_disp_all(html_disp_lambda);
 
   gbfprintf(file_out, "</body>");
   gbfprintf(file_out, "</html>");
 
 }
-
-
-ff_vecs_t html_vecs = {
-  ff_type_file,
-  { ff_cap_write, ff_cap_none, ff_cap_none },
-  nullptr,
-  wr_init,
-  nullptr,
-  wr_deinit,
-  nullptr,
-  data_write,
-  nullptr,
-  &html_args,
-  CET_CHARSET_UTF8, 0  /* CET-REVIEW */
-  , NULL_POS_OPS,
-  nullptr
-};
diff --git a/html.h b/html.h
new file mode 100644 (file)
index 0000000..0c74dca
--- /dev/null
+++ b/html.h
@@ -0,0 +1,106 @@
+/*
+    Output only format for Human Readable formats.
+
+    Copyright (C) 2004 Scott Brynen, scott (at) brynen.com
+    Copyright (C) 2002 Robert Lipe, robertlipe+source@gpsbabel.org
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*/
+#ifndef HTML_H_INCLUDED_
+#define HTML_H_INCLUDED_
+
+#include <QString>   // for QString
+#include <QVector>   // for QVector
+
+#include "defs.h"    // for arglist_t, ff_cap, ARG_NOMINMAX, ARGTYPE_STRING, ARGTYPE_BOOL, Waypoint, ff_cap_none, CET_CHARSET_UTF8, ff_cap_write, ff_type, ff_type_file, short_handle
+#include "format.h"  // for Format
+#include "gbfile.h"  // for gbfile
+
+
+class HtmlFormat : public Format
+{
+public:
+  QVector<arglist_t>* get_args() override
+  {
+    return &html_args;
+  }
+
+  ff_type get_type() const override
+  {
+    return ff_type_file;
+  }
+
+  QVector<ff_cap> get_cap() const override
+  {
+    /*          waypoints,      tracks,      routes */
+    return { ff_cap_write, ff_cap_none, ff_cap_none };
+  }
+
+  QString get_encode() const override
+  {
+    return CET_CHARSET_UTF8;
+  }
+
+  int get_fixed_encode() const override
+  {
+    return 0;
+  }
+
+  void wr_init(const QString& fname) override;
+  void write() override;
+  void wr_deinit() override;
+
+private:
+  /* Member Functions */
+
+  void html_disp(const Waypoint* wpt) const;
+  void html_index(const Waypoint* wpt) const;
+
+  /* Data Members */
+
+  gbfile* file_out{};
+  short_handle mkshort_handle{};
+
+  char* stylesheet = nullptr;
+  char* html_encrypt = nullptr;
+  char* includelogs = nullptr;
+  char* degformat = nullptr;
+  char* altunits = nullptr;
+
+  QVector<arglist_t> html_args = {
+    {
+      "stylesheet", &stylesheet,
+      "Path to HTML style sheet", nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr
+    },
+    {
+      "encrypt", &html_encrypt,
+      "Encrypt hints using ROT13", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
+    },
+    {
+      "logs", &includelogs,
+      "Include groundspeak logs if present", nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
+    },
+    {
+      "degformat", &degformat,
+      "Degrees output as 'ddd', 'dmm'(default) or 'dms'", "dmm", ARGTYPE_STRING, ARG_NOMINMAX, nullptr
+    },
+    {
+      "altunits", &altunits,
+      "Units for altitude (f)eet or (m)etres", "m", ARGTYPE_STRING, ARG_NOMINMAX, nullptr
+    },
+  };
+
+};
+#endif // HTML_H_INCLUDED_
diff --git a/vecs.h b/vecs.h
index a8ba3260e512bcdcff11bd0df9a5a5190052e0f0..71b829d4ab73df2478d21258843be994a109ae99 100644 (file)
--- a/vecs.h
+++ b/vecs.h
@@ -36,6 +36,7 @@
 #include "ggv_bin.h"
 #include "globalsat_sport.h"
 #include "gpx.h"
+#include "html.h"
 #include "kml.h"
 #include "legacyformat.h"
 #include "lowranceusr.h"
@@ -68,7 +69,6 @@ extern ff_vecs_t easygps_vecs;
 extern ff_vecs_t saroute_vecs;
 extern ff_vecs_t gpl_vecs;
 extern ff_vecs_t text_vecs;
-extern ff_vecs_t html_vecs;
 extern ff_vecs_t igc_vecs;
 extern ff_vecs_t brauniger_iq_vecs;
 extern ff_vecs_t mtk_vecs;
@@ -251,7 +251,7 @@ private:
 #endif
   LegacyFormat gpl_fmt {gpl_vecs};
   LegacyFormat text_fmt {text_vecs};
-  LegacyFormat html_fmt {html_vecs};
+  HtmlFormat html_fmt;
   LegacyFormat igc_fmt {igc_vecs};
   LegacyFormat brauniger_iq_fmt {brauniger_iq_vecs};
   LegacyFormat mtk_fmt {mtk_vecs};